package practice_2025_8_20;

import java.io.*;
import java.util.*;

public class Main {
    static int[][] arr;
    static int n;

    /**
     * dd 爱旋转
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        arr = new int[n][n];
       for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                arr[i][j] = in.nextInt();
            }
       } 
       int q = in.nextInt();
       int op1 = 0; // 上下翻转
       int op2 = 0; // 左右翻转
       while(q-- > 0) {
            int x = in.nextInt();
            op1++; // 行翻转
           if (x == 1) {
               op2++; // 列翻转
            }
       }
       op1 = op1 % 2;
       op2 = op2 % 2;
       if (op1 > 0) {
           operate1();
       }
       if (op2 > 0) {
           operate2();
       }
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }
    // 上下翻转
    public static void operate1() {
        for(int i = 0; i < n / 2; i++) {
            // 交换 i 行与 n - 1 - i 行
            for(int j = 0; j < n; j++) {
                int tmp = arr[i][j];
                arr[i][j] = arr[n - 1 - i][j];
                arr[n - 1 - i][j] = tmp;
            }
        }
    }

    // 左右翻转
    public static void operate2() {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n / 2; j++) {
                int tmp = arr[i][j];
                arr[i][j] = arr[i][n - 1 - j];
                arr[i][n - 1 - j] = tmp;
            }
        }
    }


    /**
     * 小红取数
     * @param args
     */
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        long[] arr = new long[n];
        for(int i = 0; i < n; i++) {
            arr[i] = in.nextLong();
        }
        long[][] dp = new long[n + 1][k];
        // 初始化
        for(int i = 0; i <= n; i++) {
            for(int j = 0; j < k; j++) {
                dp[i][j] = (long)-1e16;
            }
        }
        dp[0][0] = 0;
        // 填表
        for(int i = 1; i <= n; i++) {
            for(int j = 0; j < k; j++) {
                dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][(int)((j - arr[i - 1] % k + k) % k)] + arr[i - 1]);
            }
        }
        if (dp[n][0] > 0) {
            System.out.println(dp[n][0]);
        } else {
            System.out.println(-1);
        }
    }
}

class Read // ⾃定义快速读⼊
{
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String next() throws IOException
    {
        while(!st.hasMoreTokens())
        {
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }

    String nextLine() throws IOException
    {
        return bf.readLine();
    }

    int nextInt() throws IOException
    {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException
    {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException
    {
        return Double.parseDouble(next());
    }
}


